﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using WJSHWebApi.DBModel;
using WJSHWebApi.InterFace;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace WJSHWebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class KwCache : ControllerBase
    {
 
        IDBInterface iDBInterface;
        public KwCache(IDBInterface dBInterface)
        {
            iDBInterface = dBInterface;
        }
        // GET: api/<KwCache>
        [HttpGet]
        public IEnumerable<KWcache_Entity> GetKWcache_Entity()
        {
            return iDBInterface.Where<KWcache_Entity>(x => x.IsEnable == true && x.IsCreat == false && x.IsHave == false);
        }

        [HttpGet]
        public KWcache_Entity GetKWcache_EntityByRemark(string Remark)
        {
            return iDBInterface.FirstOrDefault<KWcache_Entity>(x => x.IsEnable == true && x.IsCreat == false && x.Remark== Remark);
        }
        [HttpGet]
        public bool UpdataNoHave(string Remark)
        {
            var kWcache_Entity = iDBInterface.FirstOrDefault<KWcache_Entity>(x => x.IsEnable == true && x.IsCreat == false && x.Remark == Remark);
            kWcache_Entity.IsHave = false;
            return iDBInterface.Update(kWcache_Entity);
        }
        [HttpGet]
        public bool UpdataHave(string Remark,int TaskType)
        {
            var kWcache_Entity = iDBInterface.FirstOrDefault<KWcache_Entity>(x => x.IsEnable == true && x.IsCreat == false && x.Remark == Remark);
            kWcache_Entity.IsHave = true;
            kWcache_Entity.TaskType = TaskType;
            return iDBInterface.Update(kWcache_Entity);
        }

        [HttpGet]
        public IEnumerable<ZJFLCache_Entity> GetZJFLcache_Entity()
        {
            return iDBInterface.Where<ZJFLCache_Entity>(x => x.IsEnable == true && x.IsCreat == false && x.IsHave == true);
        }

        [HttpGet]
        public IEnumerable<FJFLCache_Entity> GetFJFLcache_Entity()
        {
            return iDBInterface.Where<FJFLCache_Entity>(x => x.IsEnable == true && x.IsCreat == false && x.IsHave == true);
        }

        [HttpGet]
        public IEnumerable<FCCache_Entity> GetFCCache_Entity()
        {
            return iDBInterface.Where<FCCache_Entity>(x => x.IsEnable == true && x.IsCreat == false && x.IsHave == true);
        }
    }
}
